package com.ynu.springbootappdemo.controller;

import com.ynu.springbootappdemo.common.annotation.AuthCheck;
import com.ynu.springbootappdemo.common.constant.UserConstant;
import com.ynu.springbootappdemo.common.utils.BaseResponse;
import com.ynu.springbootappdemo.common.utils.ResultUtils;
import com.ynu.springbootappdemo.model.dto.Demo;
import com.ynu.springbootappdemo.service.WebSocketService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "测试控制器")
@RestController
@RequestMapping("/hello")
@Slf4j
public class HelloController {

    @Resource
    private WebSocketService service;

    @GetMapping("/")
    @ApiOperation("测试")
    @AuthCheck(mustRole = UserConstant.DEFAULT_ROLE)
    public BaseResponse<String> hello() {
        return ResultUtils.success("hello!");
    }

    @PostMapping("/post")
    @ApiOperation("post测试")
//    @AuthCheck(mustRole = UserConstant.DEFAULT_ROLE)
    public BaseResponse<Demo> post(@ApiParam("post测试") @RequestBody Demo demo) {
        return ResultUtils.success(demo);
    }

    @GetMapping("/get")
    @ApiOperation("get测试")
//    @AuthCheck(mustRole = UserConstant.DEFAULT_ROLE)
    public BaseResponse<String> get() {
        service.sendMessage("hello websocket!");
        return ResultUtils.success("success");
    }
}
